import { PageNode } from "maishu-chitu";

let dir = 'admin/modules';

let user_forgetPassword = { name: 'user_forgetPassword', action: `${dir}/user/forgetPassword`, cache: false };
let user_login = { name: 'user_login', action: `${dir}/user/login`, cache: false };
let user_register = { name: 'user_register', action: `${dir}/user/register`, cache: false };

let anonymous = [
    user_register, user_forgetPassword, user_login
]
export let siteMap = {
    nodes: {
        home_index: { name: 'home_index', action: `${dir}/home/index`, cache: true },
        // coupon_couponList: { name: 'coupon_couponList', action: `${dir}/coupon/couponList`, cache: true },
        // coupon_couponCodeList: { name: 'coupon_couponCodeList', action: `${dir}/coupon/couponCodeList`, cache: true },
        coupon_couponEdit: { name: 'coupon_couponEdit', action: `${dir}/coupon/couponEdit`, cache: false },
        // coupon_couponSetting: { name: 'coupon_couponSetting', action: `${dir}/coupon/couponSetting`, cache: true },
        // freight_solutionList: { name: 'freight_solutionList', action: `${dir}/freight/solutionList`, cache: true },
        // freight_freightList: { name: 'freight_freightList', action: `${dir}/freight/freightList`, cache: true },
        // freight_inCitySend: { name: 'freight_inCitySend', action: `${dir}/freight/inCitySend`, cache: true },
        // member_memberList: { name: 'member_memberList', action: `${dir}/member/memberList`, cache: true },

        // user_changePassword: { name: 'user_changePassword', action: `${dir}/user/changePassword`, cache: true },
        user_login,
        user_register,
        user_forgetPassword,

        // shopping_brandList: { name: 'shopping_brandList', action: `${dir}/shopping/brandList`, cache: true },
        // shopping_categoryList: { action: `${dir}/shopping/productCategoryList`, cache: true },
        // shopping_paymentSetting: { action: `${dir}/shopping/paymentSetting`, cache: true },
        // shopping_productList: { action: `${dir}/shopping/productList`, cache: true },
        // shopping_orderList: { action: `${dir}/shopping/orderList`, cache: true },
        // shopping_promotion_activities: { action: `${dir}/shopping/promotion/activities`, cache: true },
        shopping_promotion_activityEdit: { action: `${dir}/shopping/promotion/activityEdit2`, cache: false, name: 'shopping_promotion_activityEdit' },
        shopping_product_productEdit: { action: `${dir}/shopping/product/newProductEdit`, cache: false, name: 'shopping_product_productEdit' },

        // station_index: { action: `${dir}/station/index`, cache: true },
        // station_store_home: { action: `${dir}/station/storePageDesign`, cache: true },
        // station_store_style: { action: `${dir}/station/storeStyle`, cache: true },
        // station_store_shoppingCart: { action: `${dir}/station/storePageDesign`, cache: true },
        // station_store_categories: { action: `${dir}/station/storePageDesign`, cache: true },
        // station_store_member: { action: `${dir}/station/storePageDesign`, cache: true },
        // station_store_menu: { action: `${dir}/station/storePageDesign`, cache: true },
        // station_store_coupon: { action: `${dir}/station/storePageDesign`, cache: false },
        // station_productTemplates: { action: `${dir}/shopping/product/productTemplates` },
        station_productTemplate: { action: `${dir}/shopping/product/productTemplate`, name: 'station_productTemplate' },

        station_page: { action: `${dir}/station/page`, cache: false, name: 'station_page' },
        // station_pageList: { action: `${dir}/station/pageList`, cache: true },
        // station_preView: { action: `${dir}/station/preView`, cache: false },
        station_snapshoots: { action: `${dir}/station/snapshoots`, name: 'station_snapshoots' },
        user_myStores: { action: `${dir}/user/myStores`, cache: false, name: 'user_myStores' },
        // weixin_setting: { action: `${dir}/weixin/setting`, cache: false },
        // member_roleList: { action: `${dir}/member/roleList` },
        member_role: { action: `${dir}/member/role`, name: 'member_role' },

        // finance_receivementAccount: { action: `${dir}/finance/receivementAccount` }
    },
    anonymous
}

export let pageNodes = siteMap.nodes;


export type MenuNode = {
    title?: string, icon?: string, visible?: boolean,
    children?: MenuNode[],
    parent?: MenuNode,
    name?: string,
};

export let menuData: MenuNode[] = [
    { title: '概况', icon: 'icon-dashboard', visible: true, name: 'home_index' },
    {
        title: "微店",
        icon: "icon-home",
        children: [
            { title: '店铺设置', name: 'station_index' },
            {//Object.assign(siteMap.nodes.station_store_home,
                title: '店铺首页', name: 'station_store_home',
                children: [
                    Object.assign(siteMap.nodes.station_page, { visible: false }),
                    Object.assign(siteMap.nodes.station_snapshoots, { title: "页面快照" }),
                ]
            },
            {//Object.assign(siteMap.nodes.station_store_member, 
                title: '会员主页', name: 'station_store_member'
            },
            { title: '店铺导航', name: 'station_store_menu' },
            { title: '购物车', name: 'station_store_shoppingCart' },//Object.assign(siteMap.nodes.station_store_shoppingCart, ),
            { title: '店铺风格', name: 'station_store_style' },//Object.assign(siteMap.nodes.station_store_style, { title: '店铺风格' }),
            { title: '商品类别', name: 'station_store_categories' },//Object.assign(siteMap.nodes.station_store_categories, { title: '商品类别' }),
            {
                title: '页面列表', name: 'station_pageList',
                visible: true,
                children: [
                    { title: '页面', visible: false },
                    { title: '页面', visible: false }
                ],
            },// Object.assign(siteMap.nodes.station_pageList, 
        ]
    },
    {
        title: "商品",
        icon: "icon-gift",
        children: [
            {// Object.assign(siteMap.nodes.shopping_productList,
                title: "商品列表", name: 'shopping_productList',
                children: [
                    { title: '', visible: false, name: 'shopping_product_productEdit' }//  siteMap.nodes.shopping_product_productEdit,
                ]
            },
            // Object.assign(siteMap.nodes.shopping_categoryList, { title: '商品分类' }),
            { title: "商品品牌", name: 'shopping_brandList' },//Object.assign(siteMap.nodes.shopping_brandList, 
            {//Object.assign(siteMap.nodes.station_productTemplates,
                title: "商品模板", name: 'station_productTemplates',
                children: [{ title: "添加模板", name: 'station_productTemplate' }]//Object.assign(siteMap.nodes.station_productTemplate, 
            },
        ]
    },
    {
        title: "订单",
        icon: "icon-list",
        children: [
            { title: '订单列表', name: 'shopping_orderList' }//Object.assign(siteMap.nodes.shopping_orderList, )
        ]
    },
    {
        title: '营销',
        icon: "icon-bullhorn",
        children: [
            { title: "促销活动", name: 'shopping_promotion_activities' },
            { title: "优惠券", name: 'coupon_couponList' },
            { title: "优惠码", name: 'coupon_couponCodeList' }
        ],
    },
    {
        title: "会员",
        icon: "icon-group",
        children: [
            { title: "会员列表", name: 'member_memberList' }//Object.assign(siteMap.nodes.member_memberList, ),
        ]
    },
    {
        title: "设置",
        icon: " icon-cog",
        children: [
            { title: "账号设置", name: 'user_changePassword' },//Object.assign(siteMap.nodes.user_changePassword,),
            {
                title: "运费设置",
                children: [
                    {
                        title: "快递发货", name: 'freight_solutionList',
                        children: [
                            { title: '运费设置', name: 'freight_freightList' }
                        ]
                    },
                    { title: '同城配送', name: 'freight_inCitySend' }
                ]
            },
            { title: '支付设置', name: 'shopping_paymentSetting' },
            { title: '公众号设置', name: 'weixin_setting' },
            { title: '角色管理', name: 'member_roleList' },
            { title: '员工管理', name: 'member_employeeList' },
            { title: '收款账号', name: 'finance_receivementAccount' }
        ]

    },
    {
        title: 'Others',
        children: [
            Object.assign(siteMap.nodes.user_login, { title: '登录' }),
            Object.assign(siteMap.nodes.user_register, { title: '注册' }),
            Object.assign(siteMap.nodes.user_myStores, { title: '我的店铺' }),
            Object.assign(siteMap.nodes.user_forgetPassword, { title: '忘记密码' })
        ],
        visible: false
    },
];


for (let key in siteMap.nodes) {
    siteMap.nodes[key].path = siteMap.nodes[key].action;
}

let stack = new Array<MenuNode>();
for (let i = 0; i < menuData.length; i++) {
    stack.push(menuData[i]);
}
while (stack.length > 0) {
    let node = stack.pop();
    node.children = node.children || [];
    console.log(node.name);
    node.children.forEach((c) => {
        c.parent = node;
        stack.push(c);
    })
}


